home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / glyphs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-28  |  69.5 KB  |  2,558 lines

  1. /* Generic glyph/image implementation + display tables
  2.    Copyright (C) 1994, 1995 Board of Trustees, University of Illinois
  3.    Copyright (C) 1995 Tinker Systems
  4.    Copyright (C) 1995 Ben Wing
  5.    Copyright (C) 1995 Sun Microsystems
  6.    
  7. This file is part of XEmacs.
  8.  
  9. XEmacs is free software; you can redistribute it and/or modify it
  10. under the terms of the GNU General Public License as published by the
  11. Free Software Foundation; either version 2, or (at your option) any
  12. later version.
  13.  
  14. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  15. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17. for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with XEmacs; see the file COPYING.  If not, write to the Free
  21. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23. /* Synched up with: Not in FSF. */
  24.  
  25. /* Written by Ben Wing and Chuck Thompson */
  26.  
  27. #include <config.h>
  28. #include "lisp.h"
  29.  
  30. #include "buffer.h"
  31. #include "device.h"
  32. #include "elhash.h"
  33. #include "faces.h"
  34. #include "frame.h"
  35. #include "glyphs-x.h" /* #### Should be glyphs.h.  Need to abstract. */
  36. #include "objects.h"
  37. #include "redisplay.h"
  38. #include "window.h"
  39.  
  40. Lisp_Object Qglyphp, Qimage, Qcontrib_p, Qbaseline;
  41.  
  42. /* Qtext defined in general.c */
  43. Lisp_Object Qmono_pixmap, Qcolor_pixmap, Qcursor, Qsubwindow;
  44.  
  45. Lisp_Object Vcurrent_display_table;
  46.  
  47. Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph;
  48. Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph;
  49. Lisp_Object Vxemacs_logo;
  50.  
  51. Lisp_Object Vthe_nothing_vector;
  52.  
  53. Lisp_Object Q_file, Q_data;
  54.  
  55. Lisp_Object Qicon;
  56.  
  57. DEFINE_IMAGE_INSTANTIATOR_TYPE (nothing);
  58. Lisp_Object Qnothing;
  59. DEFINE_IMAGE_INSTANTIATOR_TYPE (string);
  60. /* Qstring defined in general.c */
  61. DEFINE_IMAGE_INSTANTIATOR_TYPE (formatted_string);
  62. Lisp_Object Qformatted_string;
  63.  
  64. MAC_DEFINE (struct image_instantiator_methods *, mactemp_iitype_meth_or_given);
  65.  
  66. struct image_instantiator_type_entry
  67. {
  68.   Lisp_Object symbol;
  69.   struct image_instantiator_methods *meths;
  70. };
  71.  
  72. typedef struct image_instantiator_type_entry_dynarr_type
  73. {
  74.   Dynarr_declare (struct image_instantiator_type_entry);
  75. } image_instantiator_type_entry_dynarr;
  76.  
  77. image_instantiator_type_entry_dynarr *the_image_instantiator_type_entry_dynarr;
  78.  
  79. Lisp_Object Vimage_instantiator_type_list;
  80.  
  81. Lisp_Object Vimage_instance_type_list;
  82.  
  83. Lisp_Object Vglyph_type_list;
  84.  
  85. static Lisp_Object allocate_image_instance (Lisp_Object device);
  86. static int validate_image_instantiator (Lisp_Object instantiator,
  87.                     int no_error);
  88.  
  89.  
  90. /****************************************************************************
  91.  *                          Image Instantiators                             *
  92.  ****************************************************************************/
  93.  
  94. static struct image_instantiator_methods *
  95. decode_image_instantiator_type (Lisp_Object type, int no_error)
  96. {
  97.   int i;
  98.  
  99.   if (!SYMBOLP (type))
  100.     {
  101.       if (!no_error)
  102.     CHECK_SYMBOL (type, 0);
  103.       return 0;
  104.     }
  105.  
  106.   for (i = 0; i < Dynarr_length (the_image_instantiator_type_entry_dynarr);
  107.        i++)
  108.     {
  109.       if (EQ (type,
  110.           Dynarr_at (the_image_instantiator_type_entry_dynarr, i).symbol))
  111.     return Dynarr_at (the_image_instantiator_type_entry_dynarr, i).meths;
  112.     }
  113.  
  114.   if (!no_error)
  115.     signal_simple_error ("Invalid image-instantiator type", type);
  116.  
  117.   return 0;
  118. }
  119.  
  120. static int
  121. valid_image_instantiator_type_p (Lisp_Object type)
  122. {
  123.   if (decode_image_instantiator_type (type, 1))
  124.     return 1;
  125.   return 0;
  126. }
  127.  
  128. DEFUN ("valid-image-instantiator-type-p", Fvalid_image_instantiator_type_p,
  129.        Svalid_image_instantiator_type_p, 1, 1, 0,
  130.        "Given an IMAGE-INSTANTIATOR-TYPE, return non-nil if it is valid.\n\
  131. Valid types are some subset of 'nothing, 'string, 'formatted-string, 'xpm,\n\
  132. 'xbm, 'xface, 'gif, 'jpeg, 'png, 'autodetect, and 'subwindow, depending\n\
  133. on how XEmacs was compiled.")
  134.      (image_instantiator_type)
  135.      Lisp_Object image_instantiator_type;
  136. {
  137.   if (valid_image_instantiator_type_p (image_instantiator_type))
  138.     return Qt;
  139.   else
  140.     return Qnil;
  141. }
  142.  
  143. DEFUN ("image-instantiator-type-list", Fimage_instantiator_type_list,
  144.        Simage_instantiator_type_list,
  145.        0, 0, 0,
  146.        "Return a list of valid image-instantiator types.")
  147.      ()
  148. {
  149.   return Fcopy_sequence (Vimage_instantiator_type_list);
  150. }
  151.  
  152. void
  153. add_entry_to_image_instantiator_type_list (Lisp_Object symbol,
  154.                        struct image_instantiator_methods *
  155.                        meths)
  156. {
  157.   struct image_instantiator_type_entry entry;
  158.  
  159.   entry.symbol = symbol;
  160.   entry.meths = meths;
  161.   Dynarr_add (the_image_instantiator_type_entry_dynarr, entry);
  162.   Vimage_instantiator_type_list =
  163.     Fcons (symbol, Vimage_instantiator_type_list);
  164. }
  165.  
  166. static Lisp_Object *
  167. get_image_conversion_list (Lisp_Object device_type)
  168. {
  169.   return &decode_device_type (device_type, 0)->image_conversion_list;
  170. }
  171.  
  172. DEFUN ("set-device-type-image-conversion-list",
  173.        Fset_device_type_image_conversion_list,
  174.        Sset_device_type_image_conversion_list, 2, 2, 0,
  175.        "Set the image-conversion-list for devices of the given TYPE.\n\
  176. The image-conversion-list specifies how image instantiators that\n\
  177. are strings should be interpreted.  Each element of the list should be\n\
  178. a list of two elements (a regular expression string and a vector) or\n\
  179. a list of three elements (the preceding two plus an integer index into\n\
  180. the vector).  The string is converted to the vector associated with the\n\
  181. first matching regular expression.  If a vector index is specified, the\n\
  182. string itself is substituted into that position in the vector.\n\
  183. \n\
  184. Note: The conversion above is applied when the image instantiator is\n\
  185. added to an image specifier, not when the specifier is actually\n\
  186. instantiated.  Therefore, changing the image-conversion-list only affects\n\
  187. newly-added instantiators.  Existing instantiators in glyphs and image\n\
  188. specifiers will not be affected.")
  189.      (device_type, list)
  190.      Lisp_Object device_type, list;
  191. {
  192.   Lisp_Object tail;
  193.   Lisp_Object *imlist = get_image_conversion_list (device_type);
  194.  
  195.   /* Check the list to make sure that it only has valid entries. */
  196.  
  197.   EXTERNAL_LIST_LOOP (tail, list)
  198.     {
  199.       Lisp_Object mapping = XCAR (tail);
  200.  
  201.       /* Mapping form should be (STRING VECTOR) or (STRING VECTOR INTEGER) */
  202.       if (!CONSP (mapping) ||
  203.       !CONSP (XCDR (mapping)) ||
  204.       (!NILP (XCDR (XCDR (mapping))) &&
  205.        (!CONSP (XCDR (XCDR (mapping))) ||
  206.         !NILP (XCDR (XCDR (XCDR (mapping)))))))
  207.     signal_simple_error ("Invalid mapping form", mapping);
  208.       else
  209.     {
  210.       Lisp_Object exp = XCAR (mapping);
  211.       Lisp_Object typevec = XCAR (XCDR (mapping));
  212.       Lisp_Object pos = Qnil;
  213.       Lisp_Object newvec;
  214.       struct gcpro gcpro1;
  215.  
  216.       CHECK_STRING (exp, 0);
  217.       CHECK_VECTOR (typevec, 1);
  218.       if (!NILP (XCDR (XCDR (mapping))))
  219.         {
  220.           pos = XCAR (XCDR (XCDR (mapping)));
  221.           CHECK_INT (pos, 0);
  222.           if (XINT (pos) < 0 ||
  223.           XINT (pos) >= vector_length (XVECTOR (typevec)))
  224.         args_out_of_range_3
  225.           (pos, Qzero, make_number
  226.            (vector_length (XVECTOR (typevec)) - 1));
  227.         }
  228.       
  229.       newvec = Fcopy_sequence (typevec);
  230.       if (INTP (pos))
  231.         vector_data (XVECTOR (newvec))[XINT (pos)] = exp;
  232.       GCPRO1 (newvec);
  233.       if (!validate_image_instantiator (newvec, 0))
  234.         signal_simple_error ("Invalid image-conversion-list vector",
  235.                  typevec);
  236.       UNGCPRO;
  237.     }
  238.     }
  239.  
  240.   *imlist = Fcopy_tree (list, Qt);
  241.   return list;
  242. }
  243.  
  244. DEFUN ("device-type-image-conversion-list", Fdevice_type_image_conversion_list,
  245.        Sdevice_type_image_conversion_list, 1, 1, 0,
  246.        "Return the image-conversion-list for devices of the given TYPE.\n\
  247. The image-conversion-list specifies how to interpret image string\n\
  248. instantiators for the specified device type.  See\n\
  249. `set-device-type-image-conversion-list' for a description of its syntax.")
  250.      (device_type)
  251.      Lisp_Object device_type;
  252. {
  253.   return Fcopy_tree (*get_image_conversion_list (device_type), Qt);
  254. }
  255.  
  256. /* Process an string instantiator according to the image-conversion-list for
  257.    DEVICE_TYPE.  Returns a vector. */
  258.  
  259. static Lisp_Object
  260. process_image_string_instantiator (Lisp_Object data, Lisp_Object device_type,
  261.                    int no_error)
  262. {
  263.   Lisp_Object tail;
  264.  
  265.   LIST_LOOP (tail, *get_image_conversion_list (device_type))
  266.     {
  267.       Lisp_Object mapping = XCAR (tail);
  268.       Lisp_Object exp = XCAR (mapping);
  269.       Lisp_Object typevec = XCAR (XCDR (mapping));
  270.       
  271.       if (fast_string_match (exp, 0, data, 0, -1, no_error, 0) >= 0)
  272.     {
  273.       if (!NILP (XCDR (XCDR (mapping))))
  274.         {
  275.           int pos = XINT (XCAR (XCDR (XCDR (mapping))));
  276.           Lisp_Object newvec = Fcopy_sequence (typevec);
  277.           vector_data (XVECTOR (newvec))[pos] = data;
  278.           return newvec;
  279.         }
  280.       else
  281.         return typevec;
  282.     }
  283.     }
  284.  
  285.   
  286.   /* Oh well. */
  287.   
  288.   return Qnil;
  289. }
  290.  
  291. Lisp_Object
  292. find_keyword_in_vector_or_given (Lisp_Object vector, Lisp_Object keyword,
  293.                  Lisp_Object defalt)
  294. {
  295.   Lisp_Object *elt;
  296.   int instantiator_len;
  297.  
  298.   elt = vector_data (XVECTOR (vector));
  299.   instantiator_len = vector_length (XVECTOR (vector));
  300.  
  301.   elt++;
  302.   instantiator_len--;
  303.  
  304.   while (instantiator_len > 0)
  305.     {
  306.       if (EQ (elt[0], keyword))
  307.     return elt[1];
  308.       elt += 2;
  309.       instantiator_len -= 2;
  310.     }
  311.  
  312.   return defalt;
  313. }
  314.  
  315. Lisp_Object
  316. find_keyword_in_vector (Lisp_Object vector, Lisp_Object keyword)
  317. {
  318.   return find_keyword_in_vector_or_given (vector, keyword, Qnil);
  319. }
  320.  
  321. int
  322. valid_string_p (Lisp_Object data, int no_error)
  323. {
  324.   if (!STRINGP (data))
  325.     {
  326.       if (!no_error)
  327.     CHECK_STRING (data, 0);
  328.       return 0;
  329.     }
  330.  
  331.   return 1;
  332. }
  333.  
  334. int
  335. valid_int_p (Lisp_Object data, int no_error)
  336. {
  337.   if (!INTP (data))
  338.     {
  339.       if (!no_error)
  340.     CHECK_INT (data, 0);
  341.       return 0;
  342.     }
  343.  
  344.   return 1;
  345. }
  346.  
  347. int
  348. file_or_data_must_be_present (Lisp_Object instantiator, int no_error)
  349. {
  350.   if (NILP (find_keyword_in_vector (instantiator, Q_file)) &&
  351.       NILP (find_keyword_in_vector (instantiator, Q_data)))
  352.     {
  353.       if (!no_error)
  354.     signal_simple_error ("Must supply either :file or :data",
  355.                  instantiator);
  356.       return 0;
  357.     }
  358.  
  359.   return 1;
  360. }
  361.  
  362. int
  363. data_must_be_present (Lisp_Object instantiator, int no_error)
  364. {
  365.   if (NILP (find_keyword_in_vector (instantiator, Q_data)))
  366.     {
  367.       if (!no_error)
  368.     signal_simple_error ("Must supply :data", instantiator);
  369.       return 0;
  370.     }
  371.  
  372.   return 1;
  373. }
  374.  
  375. /* utility function useful in retrieving data from a file. */
  376.  
  377. Lisp_Object
  378. make_string_from_file (Lisp_Object file)
  379. {
  380.   int count = specpdl_depth ();
  381.   Lisp_Object temp_buffer;
  382.   struct gcpro gcpro1;
  383.   Lisp_Object data;
  384.   
  385.   specbind (Qinhibit_quit, Qt);
  386.   record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
  387.   temp_buffer = Fget_buffer_create (build_string (" *pixmap conversion*"));
  388.   GCPRO1 (temp_buffer);
  389.   set_buffer_internal (XBUFFER (temp_buffer));
  390.   Ferase_buffer (Fcurrent_buffer ());
  391.   /* #### need to catch errors here */
  392.   Finsert_file_contents_internal (file, Qnil, Qnil, Qnil, Qnil);
  393.   data = Fbuffer_substring (Qnil, Qnil, Fcurrent_buffer ());
  394.   unbind_to (count, Qnil);
  395.   UNGCPRO;
  396.   return data;
  397. }
  398.  
  399. /* The following two functions are provided to make it easier for
  400.    the normalize methods to work with keyword-value vectors.
  401.    Hash tables are kind of heavyweight for this purpose.
  402.    (If vectors were resizable, we could avoid this problem;
  403.    but they're not.) An alternative approach that might be
  404.    more efficient but require more work is to use a type of
  405.    assoc-Dynarr and provide primitives for deleting elements out
  406.    of it. (However, you'd also have to add an unwind-protect
  407.    to make sure the Dynarr got freed in case of an error in
  408.    the normalization process.) */
  409.  
  410. Lisp_Object
  411. tagged_vector_to_alist (Lisp_Object vector)
  412. {
  413.   Lisp_Object *elt = vector_data (XVECTOR (vector));
  414.   int len = vector_length (XVECTOR (vector));
  415.   Lisp_Object result = Qnil;
  416.  
  417.   assert (len & 1);
  418.   for (len -= 2; len >= 1; len -= 2)
  419.     result = Fcons (Fcons (elt[len], elt[len+1]), result);
  420.  
  421.   return result;
  422. }
  423.  
  424. Lisp_Object
  425. alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist)
  426. {
  427.   int len = 1 + 2 * XINT (Flength (alist));
  428.   Lisp_Object *elt = alloca (len * sizeof (Lisp_Object));
  429.   int i;
  430.   Lisp_Object rest;
  431.  
  432.   i = 0;
  433.   elt[i++] = tag;
  434.   LIST_LOOP (rest, alist)
  435.     {
  436.       Lisp_Object pair = XCAR (rest);
  437.       elt[i] = XCAR (pair);
  438.       elt[i+1] = XCDR (pair);
  439.       i += 2;
  440.     }
  441.  
  442.   return Fvector (len, elt);
  443. }
  444.  
  445. static int
  446. validate_image_instantiator (Lisp_Object instantiator, int no_error)
  447. {
  448.   if (STRINGP (instantiator))
  449.     return 1;
  450.   else if (VECTORP (instantiator))
  451.     {
  452.       Lisp_Object *elt = vector_data (XVECTOR (instantiator));
  453.       int instantiator_len = XVECTOR (instantiator)->size;
  454.       struct image_instantiator_methods *meths;
  455.       Lisp_Object already_seen = Qnil;
  456.       struct gcpro gcpro1;
  457.       int i;
  458.  
  459.       if (instantiator_len < 1)
  460.     {
  461.       if (!no_error)
  462.         signal_simple_error ("Vector length must be at least 1",
  463.                  instantiator);
  464.       return 0;
  465.     }
  466.  
  467.       meths = decode_image_instantiator_type (elt[0], no_error);
  468.       if (!meths)
  469.     /* Errors already reported */
  470.     return 0;
  471.  
  472.       if (!(instantiator_len & 1))
  473.     {
  474.       if (!no_error)
  475.         signal_simple_error ("Must have alternating keyword/value pairs",
  476.                  instantiator);
  477.       return 0;
  478.     }
  479.  
  480.       GCPRO1 (already_seen);
  481.  
  482.       for (i = 1; i < instantiator_len; i += 2)
  483.     {
  484.       Lisp_Object keyword = elt[i];
  485.       Lisp_Object value = elt[i+1];
  486.       int j;
  487.  
  488.       if (!SYMBOLP (keyword))
  489.         {
  490.           if (!no_error)
  491.         CHECK_SYMBOL (keyword, 0);
  492.           break;
  493.         }
  494.  
  495.       if (!SYMBOL_IS_KEYWORD (keyword))
  496.         {
  497.           if (!no_error)
  498.         signal_simple_error ("Symbol must begin with a colon",
  499.                      keyword);
  500.           break;
  501.         }
  502.  
  503.       for (j = 0; j < Dynarr_length (meths->keywords); j++)
  504.         if (EQ (keyword, Dynarr_at (meths->keywords, j).keyword))
  505.           break;
  506.  
  507.       if (j == Dynarr_length (meths->keywords))
  508.         {
  509.           if (!no_error)
  510.         signal_simple_error ("Unrecognized keyword", keyword);
  511.           break;
  512.         }
  513.  
  514.       if (!Dynarr_at (meths->keywords, j).multiple_p)
  515.         {
  516.           if (!NILP (memq_no_quit (keyword, already_seen)))
  517.         {
  518.           if (!no_error)
  519.             signal_simple_error
  520.               ("Keyword may not appear more than once", keyword);
  521.           break;
  522.         }
  523.           already_seen = Fcons (keyword, already_seen);
  524.         }
  525.  
  526.       if (! (Dynarr_at (meths->keywords, j).validate) (value, no_error))
  527.         {
  528.           if (!no_error)
  529.         /* No explanatory error provided */
  530.         signal_simple_error_2 ("Invalid value for keyword", keyword,
  531.                        value);
  532.           break;
  533.         }
  534.     }
  535.  
  536.       UNGCPRO;
  537.  
  538.       if (i < instantiator_len)
  539.     return 0;
  540.  
  541.       if (!IITYPE_METH_OR_GIVEN (meths, validate, (instantiator, no_error), 1))
  542.     {
  543.       if (!no_error)
  544.         signal_simple_error ("Something wrong with instantiator",
  545.                  instantiator);
  546.       return 0;
  547.     }
  548.  
  549.       return 1;
  550.     }
  551.   else if (!no_error)
  552.     signal_simple_error ("Must be string or vector", instantiator);
  553.  
  554.   return 0;
  555. }
  556.  
  557. static Lisp_Object
  558. normalize_image_instantiator (Lisp_Object instantiator, Lisp_Object devtype,
  559.                   int no_error)
  560. {
  561.   if (STRINGP (instantiator))
  562.     {
  563.       instantiator =
  564.     process_image_string_instantiator (instantiator, devtype, 1);
  565.       if (NILP (instantiator))
  566.     return Qnil;
  567.     }
  568.  
  569.   assert (VECTORP (instantiator));
  570.   /* We have to always store the actual pixmap data and not the
  571.      filename even though this is a potential memory pig.  We have to
  572.      do this because it is quite possible that we will need to
  573.      instantiate a new instance of the pixmap and the file will no
  574.      longer exist (e.g. w3 pixmaps are almost always from temporary
  575.      files). */
  576.   instantiator =
  577.     IITYPE_METH_OR_GIVEN
  578.       (decode_image_instantiator_type
  579.        (vector_data (XVECTOR (instantiator))[0], 1),
  580.        normalize, (instantiator, devtype, no_error), instantiator);
  581.  
  582.   return instantiator;
  583. }
  584.  
  585. static Lisp_Object
  586. instantiate_image_instantiator (Lisp_Object device, Lisp_Object instantiator,
  587.                 int dest_mask, int no_error)
  588. {
  589.   Lisp_Object ii;
  590.   int retval = 0;
  591.   struct gcpro gcpro1;
  592.  
  593.   ii = allocate_image_instance (device);
  594.  
  595.   GCPRO1 (ii);
  596.   retval = IITYPE_METH_OR_GIVEN
  597.     (decode_image_instantiator_type
  598.      (vector_data (XVECTOR (instantiator))[0], 1),
  599.      instantiate, (ii, instantiator, dest_mask, no_error), 0);
  600.   UNGCPRO;
  601.  
  602.   if (!retval)
  603.     return Qnil;
  604.  
  605.   return ii;
  606. }
  607.  
  608.  
  609. /****************************************************************************
  610.  *                                  nothing                                 *
  611.  ****************************************************************************/
  612.  
  613. static int
  614. nothing_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
  615.              int dest_mask, int no_error)
  616. {
  617.   struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
  618.  
  619.   if (dest_mask & IMAGE_NOTHING_MASK)
  620.     {
  621.       IMAGE_INSTANCE_TYPE (ii) = IMAGE_NOTHING;
  622.       return 1;
  623.     }
  624.   else
  625.     {
  626.       if (!no_error)
  627.     signal_simple_error ("No compatible image-instance types given",
  628.                  instantiator);
  629.       return 0;
  630.     }
  631. }
  632.  
  633.  
  634. /****************************************************************************
  635.  *                             formatted-string                             *
  636.  ****************************************************************************/
  637.  
  638. static int
  639. string_validate (Lisp_Object instantiator, int no_error)
  640. {
  641.   return data_must_be_present (instantiator, no_error);
  642. }
  643.  
  644. static int
  645. string_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
  646.             int dest_mask, int no_error)
  647. {
  648.   Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
  649.   struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
  650.  
  651.   assert (!NILP (data));
  652.   if (dest_mask & IMAGE_TEXT_MASK)
  653.     {
  654.       IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
  655.       IMAGE_INSTANCE_TEXT_STRING (ii) = data;
  656.       return 1;
  657.     }
  658.   else
  659.     {
  660.       if (!no_error)
  661.     signal_simple_error ("No compatible image-instance types given",
  662.                  instantiator);
  663.       return 0;
  664.     }
  665. }
  666.  
  667.  
  668. /****************************************************************************
  669.  *                                  string                                  *
  670.  ****************************************************************************/
  671.  
  672. static int
  673. formatted_string_validate (Lisp_Object instantiator, int no_error)
  674. {
  675.   return data_must_be_present (instantiator, no_error);
  676. }
  677.  
  678. static int
  679. formatted_string_instantiate (Lisp_Object image_instance,
  680.                   Lisp_Object instantiator,
  681.                   int dest_mask, int no_error)
  682. {
  683.   Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
  684.   struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
  685.  
  686.   assert (!NILP (data));
  687.   /* #### implement this */
  688.   warn_when_safe (Qunimplemented, Qnotice,
  689.           "`formatted-string' not yet implemented; assuming `string'");
  690.   if (dest_mask & IMAGE_TEXT_MASK)
  691.     {
  692.       IMAGE_INSTANCE_TYPE (ii) = IMAGE_TEXT;
  693.       IMAGE_INSTANCE_TEXT_STRING (ii) = data;
  694.       return 1;
  695.     }
  696.   else
  697.     {
  698.       if (!no_error)
  699.     signal_simple_error ("No compatible image-instance types given",
  700.                  instantiator);
  701.       return 0;
  702.     }
  703. }
  704.  
  705.  
  706. /****************************************************************************
  707.  *                          Image-Instance Object                           *
  708.  ****************************************************************************/
  709.  
  710. Lisp_Object Qimage_instancep;
  711. static Lisp_Object mark_image_instance (Lisp_Object, void (*) (Lisp_Object));
  712. static void print_image_instance (Lisp_Object, Lisp_Object, int);
  713. static void finalize_image_instance (void *, int);
  714. static int image_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth);
  715. static unsigned long image_instance_hash (Lisp_Object obj, int depth);
  716. DEFINE_LRECORD_IMPLEMENTATION ("image-instance", image_instance,
  717.                    mark_image_instance, print_image_instance,
  718.                    finalize_image_instance, image_instance_equal,
  719.                    image_instance_hash,
  720.                    struct Lisp_Image_Instance);
  721. static Lisp_Object
  722. mark_image_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
  723. {
  724.   struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
  725.  
  726.   (markobj) (i->name);
  727.   switch (IMAGE_INSTANCE_TYPE (i))
  728.     {
  729.     case IMAGE_TEXT:
  730.       (markobj) (IMAGE_INSTANCE_TEXT_STRING (i));
  731.       break;
  732.     case IMAGE_MONO_PIXMAP:
  733.     case IMAGE_COLOR_PIXMAP:
  734.       (markobj) (IMAGE_INSTANCE_PIXMAP_FILENAME (i));
  735.       (markobj) (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i));
  736.       (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i));
  737.       (markobj) (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i));
  738.       break;
  739.     case IMAGE_SUBWINDOW:
  740.       /* #### implement me */
  741.       break;
  742.     default:
  743.       break;
  744.     }
  745.  
  746.   MAYBE_DEVMETH (XDEVICE (i->device), mark_image_instance, (i, markobj));
  747.  
  748.   return (i->device);
  749. }
  750.  
  751. static void
  752. print_image_instance (Lisp_Object obj, Lisp_Object printcharfun,
  753.               int escapeflag)
  754. {
  755.   char buf[100];
  756.   struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (obj);
  757.  
  758.   if (print_readably)
  759.     error ("printing unreadable object #<image-instance 0x%x>",
  760.            ii->header.uid);
  761.   write_c_string ("#<image-instance (", printcharfun);
  762.   print_internal (Fimage_instance_type (obj), printcharfun, 0);
  763.   write_c_string (") ", printcharfun);
  764.   if (!NILP (ii->name))
  765.     {
  766.       print_internal (ii->name, printcharfun, 1);
  767.       write_c_string (" ", printcharfun);
  768.     }
  769.   write_c_string ("on ", printcharfun);
  770.   print_internal (ii->device, printcharfun, 0);
  771.   write_c_string (" ", printcharfun);
  772.   switch (IMAGE_INSTANCE_TYPE (ii))
  773.     {
  774.     case IMAGE_NOTHING:
  775.       break;
  776.  
  777.     case IMAGE_TEXT:
  778.       print_internal (IMAGE_INSTANCE_TEXT_STRING (ii), printcharfun, 1);
  779.       break;
  780.  
  781.     case IMAGE_MONO_PIXMAP:
  782.     case IMAGE_COLOR_PIXMAP:
  783.     case IMAGE_CURSOR:
  784.       if (STRINGP (IMAGE_INSTANCE_PIXMAP_FILENAME (ii)))
  785.     {
  786.       char *s;
  787.       Lisp_Object filename = IMAGE_INSTANCE_PIXMAP_FILENAME (ii);
  788.       s = strrchr ((char *) string_data (XSTRING (filename)), '/');
  789.       if (s)
  790.         print_internal (build_string (s + 1), printcharfun, 1);
  791.       else
  792.         print_internal (filename, printcharfun, 1);
  793.     }
  794.       if (IMAGE_INSTANCE_PIXMAP_DEPTH (ii) > 1)
  795.     sprintf (buf, " %dx%dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
  796.          IMAGE_INSTANCE_PIXMAP_HEIGHT (ii),
  797.          IMAGE_INSTANCE_PIXMAP_DEPTH (ii));
  798.       else
  799.     sprintf (buf, " %dx%d", IMAGE_INSTANCE_PIXMAP_WIDTH (ii),
  800.          IMAGE_INSTANCE_PIXMAP_HEIGHT (ii));
  801.       write_c_string (buf, printcharfun);
  802.       if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ||
  803.       !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
  804.     {
  805.       write_c_string (" @", printcharfun);
  806.       if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)))
  807.         {
  808.           sprintf (buf, "%d", XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)));
  809.           write_c_string (buf, printcharfun);
  810.         }
  811.       else
  812.         write_c_string ("??", printcharfun);
  813.       write_c_string (",", printcharfun);
  814.       if (!NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)))
  815.         {
  816.           sprintf (buf, "%d", XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)));
  817.           write_c_string (buf, printcharfun);
  818.         }
  819.       else
  820.         write_c_string ("??", printcharfun);
  821.     }
  822.       break;
  823.  
  824.     case IMAGE_SUBWINDOW:
  825.       /* #### implement me */
  826.       break;
  827.  
  828.     default:
  829.       abort ();
  830.     }
  831.  
  832.   MAYBE_DEVMETH (XDEVICE (ii->device), print_image_instance,
  833.          (ii, printcharfun, escapeflag));
  834.   sprintf (buf, " 0x%x>", ii->header.uid);
  835.   write_c_string (buf, printcharfun);
  836. }
  837.  
  838. static void
  839. finalize_image_instance (void *header, int for_disksave)
  840. {
  841.   struct Lisp_Image_Instance *i = (struct Lisp_Image_Instance *) header;
  842.  
  843.   if (for_disksave) finalose (i);
  844.  
  845.   MAYBE_DEVMETH (XDEVICE (i->device), finalize_image_instance, (i));
  846. }
  847.  
  848. static int
  849. image_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
  850. {
  851.   struct Lisp_Image_Instance *i1 = XIMAGE_INSTANCE (o1);
  852.   struct Lisp_Image_Instance *i2 = XIMAGE_INSTANCE (o2);
  853.   struct device *d1 = XDEVICE (i1->device);
  854.   struct device *d2 = XDEVICE (i2->device);
  855.  
  856.   if (d1 != d2)
  857.     return 0;
  858.   if (IMAGE_INSTANCE_TYPE (i1) != IMAGE_INSTANCE_TYPE (i2))
  859.     return 0;
  860.   if (!internal_equal (IMAGE_INSTANCE_NAME (i1), IMAGE_INSTANCE_NAME (i2),
  861.                depth + 1))
  862.     return 0;
  863.  
  864.   switch (IMAGE_INSTANCE_TYPE (i1))
  865.     {
  866.     case IMAGE_NOTHING:
  867.       break;
  868.  
  869.     case IMAGE_TEXT:
  870.       if (!internal_equal (IMAGE_INSTANCE_TEXT_STRING (i1),
  871.                IMAGE_INSTANCE_TEXT_STRING (i2),
  872.                depth + 1))
  873.     return 0;
  874.       break;
  875.  
  876.     case IMAGE_MONO_PIXMAP:
  877.     case IMAGE_COLOR_PIXMAP:
  878.     case IMAGE_CURSOR:
  879.       if (!(IMAGE_INSTANCE_PIXMAP_WIDTH (i1) ==
  880.         IMAGE_INSTANCE_PIXMAP_WIDTH (i2) &&
  881.         IMAGE_INSTANCE_PIXMAP_HEIGHT (i1) ==
  882.         IMAGE_INSTANCE_PIXMAP_HEIGHT (i2) &&
  883.         IMAGE_INSTANCE_PIXMAP_DEPTH (i1) ==
  884.         IMAGE_INSTANCE_PIXMAP_DEPTH (i2) &&
  885.         EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i1),
  886.         IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (i2)) &&
  887.         EQ (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i1),
  888.         IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (i2)) &&
  889.         internal_equal (IMAGE_INSTANCE_PIXMAP_FILENAME (i1),
  890.                 IMAGE_INSTANCE_PIXMAP_FILENAME (i2),
  891.                 depth + 1) &&
  892.         internal_equal (IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i1),
  893.                 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (i2),
  894.                 depth + 1)))
  895.     return 0;
  896.       break;
  897.  
  898.     case IMAGE_SUBWINDOW:
  899.       /* #### implement me */
  900.       break;
  901.  
  902.     default:
  903.       abort ();
  904.     }
  905.  
  906.   return DEVMETH_OR_GIVEN (d1, image_instance_equal, (i1, i2, depth), 1);
  907. }
  908.  
  909. static unsigned long
  910. image_instance_hash (Lisp_Object obj, int depth)
  911. {
  912.   struct Lisp_Image_Instance *i = XIMAGE_INSTANCE (obj);
  913.   struct device *d = XDEVICE (i->device);
  914.   unsigned long hash = (unsigned long) d;
  915.  
  916.   switch (IMAGE_INSTANCE_TYPE (i))
  917.     {
  918.     case IMAGE_NOTHING:
  919.       break;
  920.  
  921.     case IMAGE_TEXT:
  922.       hash = HASH2 (hash, internal_hash (IMAGE_INSTANCE_TEXT_STRING (i),
  923.                      depth + 1));
  924.       break;
  925.  
  926.     case IMAGE_MONO_PIXMAP:
  927.     case IMAGE_COLOR_PIXMAP:
  928.     case IMAGE_CURSOR:
  929.       hash = HASH5 (hash, IMAGE_INSTANCE_PIXMAP_WIDTH (i),
  930.             IMAGE_INSTANCE_PIXMAP_HEIGHT (i),
  931.             IMAGE_INSTANCE_PIXMAP_DEPTH (i),
  932.             internal_hash (IMAGE_INSTANCE_PIXMAP_FILENAME (i),
  933.                    depth + 1));
  934.       break;
  935.  
  936.     case IMAGE_SUBWINDOW:
  937.       /* #### implement me */
  938.       break;
  939.  
  940.     default:
  941.       abort ();
  942.     }
  943.  
  944.   return HASH2 (hash, DEVMETH_OR_GIVEN (d, image_instance_hash, (i, depth),
  945.                     0));
  946. }
  947.  
  948. static Lisp_Object
  949. allocate_image_instance (Lisp_Object device)
  950. {
  951.   struct Lisp_Image_Instance *lp =
  952.     alloc_lcrecord (sizeof (struct Lisp_Image_Instance),
  953.             lrecord_image_instance);
  954.   Lisp_Object val = Qnil;
  955.  
  956.   zero_lcrecord (lp);
  957.   lp->device = device;
  958.   lp->type = IMAGE_NOTHING;
  959.   lp->name = Qnil;
  960.   XSETIMAGE_INSTANCE (val, lp);
  961.   return val;
  962. }
  963.  
  964. static enum image_instance_type
  965. decode_image_instance_type (Lisp_Object type, int no_error)
  966. {
  967.   if (!no_error)
  968.     CHECK_SYMBOL (type, 0);
  969.  
  970.   if (EQ (type, Qnothing))
  971.     return IMAGE_NOTHING;
  972.   if (EQ (type, Qtext))
  973.     return IMAGE_TEXT;
  974.   if (EQ (type, Qmono_pixmap))
  975.     return IMAGE_MONO_PIXMAP;
  976.   if (EQ (type, Qcolor_pixmap))
  977.     return IMAGE_COLOR_PIXMAP;
  978.   if (EQ (type, Qcursor))
  979.     return IMAGE_CURSOR;
  980.   if (EQ (type, Qsubwindow))
  981.     return IMAGE_SUBWINDOW;
  982.  
  983.   if (!no_error)
  984.     signal_simple_error ("Invalid image-instance type", type);
  985.   return IMAGE_UNKNOWN;
  986. }
  987.  
  988. static int
  989. image_instance_type_to_mask (enum image_instance_type type)
  990. {
  991.   /* This depends on the fact that enums are assigned consecutive
  992.      integers starting at 0. (Remember that IMAGE_UNKNOWN is the
  993.      first enum.) I'm fairly sure this behavior in ANSI-mandated,
  994.      so there should be no portability problems here. */
  995.   return (1 << ((int) (type) - 1));
  996. }
  997.  
  998. static int
  999. decode_image_instance_type_list (Lisp_Object list, int no_error)
  1000. {
  1001.   Lisp_Object rest;
  1002.   int mask = 0;
  1003.  
  1004.   if (NILP (list))
  1005.     return ~0;
  1006.  
  1007.   if (!CONSP (list))
  1008.     {
  1009.       enum image_instance_type type = decode_image_instance_type (list,
  1010.                                   no_error);
  1011.       if (type == IMAGE_UNKNOWN)
  1012.     return 0;
  1013.       return image_instance_type_to_mask (type);
  1014.     }
  1015.  
  1016.   EXTERNAL_LIST_LOOP (rest, list)
  1017.     {
  1018.       enum image_instance_type type = decode_image_instance_type (XCAR (rest),
  1019.                                   no_error);
  1020.       if (type == IMAGE_UNKNOWN)
  1021.     return 0;
  1022.       mask |= image_instance_type_to_mask (type);
  1023.     }
  1024.  
  1025.   return mask;
  1026. }
  1027.  
  1028. static int
  1029. valid_image_instance_type_p (Lisp_Object type)
  1030. {
  1031.   if (!NILP (memq_no_quit (type, Vimage_instance_type_list)))
  1032.     return 1;
  1033.   return 0;
  1034. }
  1035.  
  1036. DEFUN ("valid-image-instance-type-p", Fvalid_image_instance_type_p,
  1037.        Svalid_image_instance_type_p, 1, 1, 0,
  1038.        "Given an IMAGE-INSTANCE-TYPE, return non-nil if it is valid.\n\
  1039. Valid types are some subset of 'nothing, 'text, 'mono-pixmap, 'color-pixmap,\n\
  1040. 'cursor, and 'subwindow, depending on how XEmacs was compiled.")
  1041.      (image_instance_type)
  1042.      Lisp_Object image_instance_type;
  1043. {
  1044.   if (valid_image_instance_type_p (image_instance_type))
  1045.     return Qt;
  1046.   else
  1047.     return Qnil;
  1048. }
  1049.  
  1050. DEFUN ("image-instance-type-list", Fimage_instance_type_list,
  1051.        Simage_instance_type_list,
  1052.        0, 0, 0,
  1053.        "Return a list of valid image-instance types.")
  1054.      ()
  1055. {
  1056.   return Fcopy_sequence (Vimage_instance_type_list);
  1057. }
  1058.  
  1059. DEFUN ("make-image-instance", Fmake_image_instance, Smake_image_instance,
  1060.        1, 4, 0,
  1061.        "Create a new `image-instance' object.\n\
  1062. \n\
  1063. Image-instance objects encapsulate the way a particular image (pixmap,\n\
  1064. etc.) is displayed on a particular device.  In most circumstances, you\n\
  1065. do not need to directly create image instances; use a glyph or an image-\n\
  1066. specifier instead. (Most functions and data structures that want an image\n\
  1067. are designed to take either a glyph or an image-specifier.)\n\
  1068. \n\
  1069. DATA is an image instantiator; see `image-specifier-p' for a description\n\
  1070. of the allowed values.")
  1071.   (data, device, dest_types, no_error)
  1072.   Lisp_Object data, device, dest_types, no_error;
  1073. {
  1074.   Lisp_Object ii;
  1075.   struct gcpro gcpro1;
  1076.   int dest_mask;
  1077.  
  1078.   XSETDEVICE (device, get_device (device));
  1079.  
  1080.   if (!validate_image_instantiator (data, !NILP (no_error)))
  1081.     return Qnil;
  1082.  
  1083.   dest_mask = decode_image_instance_type_list (dest_types, !NILP (no_error));
  1084.   if (!dest_mask)
  1085.     return Qnil;
  1086.  
  1087.   data = normalize_image_instantiator (data, Fdevice_type (device),
  1088.                        !NILP (no_error));
  1089.   if (NILP (data))
  1090.     return Qnil;
  1091.  
  1092.   GCPRO1 (data);
  1093.   ii = instantiate_image_instantiator (device, data, dest_mask,
  1094.                        !NILP (no_error));
  1095.   RETURN_UNGCPRO (ii);
  1096. }
  1097.  
  1098. DEFUN ("image-instance-p", Fimage_instance_p, Simage_instance_p, 1, 1, 0,
  1099.        "Return non-nil if OBJECT is an image instance.")
  1100.   (object)
  1101.   Lisp_Object object;
  1102. {
  1103.   return (IMAGE_INSTANCEP (object) ? Qt : Qnil);
  1104. }
  1105.  
  1106. DEFUN ("image-instance-type", Fimage_instance_type, Simage_instance_type,
  1107.        1, 1, 0,
  1108.        "Return the type of the given image instance.\n\
  1109. The return value will be one of 'nothing, 'text, 'mono-pixmap,\n\
  1110. 'color-pixmap, 'cursor, or 'subwindow.")
  1111.   (image_instance)
  1112.   Lisp_Object image_instance;
  1113. {
  1114.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1115.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1116.     {
  1117.     case IMAGE_NOTHING:
  1118.       return Qnothing;
  1119.     case IMAGE_TEXT:
  1120.       return Qtext;
  1121.     case IMAGE_MONO_PIXMAP:
  1122.       return Qmono_pixmap;
  1123.     case IMAGE_COLOR_PIXMAP:
  1124.       return Qcolor_pixmap;
  1125.     case IMAGE_CURSOR:
  1126.       return Qcursor;
  1127.     case IMAGE_SUBWINDOW:
  1128.       return Qsubwindow;
  1129.     default:
  1130.       abort ();
  1131.     }
  1132.  
  1133.   return Qnil; /* not reached */
  1134. }
  1135.  
  1136. DEFUN ("image-instance-name", Fimage_instance_name,
  1137.        Simage_instance_name, 1, 1, 0,
  1138.       "Return the name of the given image instance.")
  1139.   (image_instance)
  1140.   Lisp_Object image_instance;
  1141. {
  1142.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1143.   return (XIMAGE_INSTANCE_NAME (image_instance));
  1144. }
  1145.  
  1146. DEFUN ("image-instance-string", Fimage_instance_string,
  1147.        Simage_instance_string, 1, 1, 0,
  1148.       "Return the string of the given image instance.")
  1149.   (image_instance)
  1150.   Lisp_Object image_instance;
  1151. {
  1152.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1153.   return (XIMAGE_INSTANCE_TEXT_STRING (image_instance));
  1154. }
  1155.  
  1156. DEFUN ("image-instance-file-name", Fimage_instance_file_name,
  1157.        Simage_instance_file_name, 1, 1, 0,
  1158.   "Return the file name from which IMAGE-INSTANCE was read, if known.")
  1159.   (image_instance)
  1160.   Lisp_Object image_instance;
  1161. {
  1162.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1163.  
  1164.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1165.     {
  1166.     case IMAGE_MONO_PIXMAP:
  1167.     case IMAGE_COLOR_PIXMAP:
  1168.     case IMAGE_CURSOR:
  1169.       return XIMAGE_INSTANCE_PIXMAP_FILENAME (image_instance);
  1170.  
  1171.     default:
  1172.       return Qnil;
  1173.     }
  1174. }
  1175.  
  1176. DEFUN ("image-instance-mask-file-name", Fimage_instance_mask_file_name,
  1177.        Simage_instance_mask_file_name, 1, 1, 0,
  1178.   "Return the file name from which IMAGE-INSTANCE's mask was read, if known.")
  1179.   (image_instance)
  1180.   Lisp_Object image_instance;
  1181. {
  1182.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1183.  
  1184.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1185.     {
  1186.     case IMAGE_MONO_PIXMAP:
  1187.     case IMAGE_COLOR_PIXMAP:
  1188.     case IMAGE_CURSOR:
  1189.       return XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME (image_instance);
  1190.  
  1191.     default:
  1192.       return Qnil;
  1193.     }
  1194. }
  1195.  
  1196. DEFUN ("image-instance-depth", Fimage_instance_depth,
  1197.        Simage_instance_depth, 1, 1, 0,
  1198.        "Return the depth of the image instance.\n\
  1199. This is 0 for a bitmap, or a positive integer for a pixmap.")
  1200.      (image_instance)
  1201.      Lisp_Object image_instance;
  1202. {
  1203.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1204.  
  1205.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1206.     {
  1207.     case IMAGE_MONO_PIXMAP:
  1208.     case IMAGE_COLOR_PIXMAP:
  1209.     case IMAGE_CURSOR:
  1210.       return (make_number (XIMAGE_INSTANCE_PIXMAP_DEPTH (image_instance)));
  1211.  
  1212.     default:
  1213.       return Qnil;
  1214.     }
  1215. }
  1216.  
  1217. DEFUN ("image-instance-height", Fimage_instance_height,
  1218.        Simage_instance_height, 1, 1, 0,
  1219.        "Return the height of the image instance, in pixels.")
  1220.      (image_instance)
  1221.      Lisp_Object image_instance;
  1222. {
  1223.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1224.  
  1225.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1226.     {
  1227.     case IMAGE_MONO_PIXMAP:
  1228.     case IMAGE_COLOR_PIXMAP:
  1229.     case IMAGE_CURSOR:
  1230.       return (make_number (XIMAGE_INSTANCE_PIXMAP_HEIGHT (image_instance)));
  1231.  
  1232.     default:
  1233.       return Qnil;
  1234.     }
  1235. }
  1236.  
  1237. DEFUN ("image-instance-width", Fimage_instance_width,
  1238.        Simage_instance_width, 1, 1, 0,
  1239.        "Return the width of the image instance, in pixels.")
  1240.      (image_instance)
  1241.      Lisp_Object image_instance;
  1242. {
  1243.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1244.  
  1245.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1246.     {
  1247.     case IMAGE_MONO_PIXMAP:
  1248.     case IMAGE_COLOR_PIXMAP:
  1249.     case IMAGE_CURSOR:
  1250.       return (make_number (XIMAGE_INSTANCE_PIXMAP_WIDTH (image_instance)));
  1251.  
  1252.     default:
  1253.       return Qnil;
  1254.     }
  1255. }
  1256.  
  1257. DEFUN ("set-image-instance-hotspot", Fset_image_instance_hotspot,
  1258.        Sset_image_instance_hotspot,
  1259.        3, 3, 0,
  1260.        "Set the image instance's hotspot.\n\
  1261. This is a point relative to the origin of the pixmap.  When a pixmap is\n\
  1262. used as a cursor or similar pointing indicator, the hotspot is the point\n\
  1263. on the pixmap that sits over the location that the pointer points to.\n\
  1264. This is, for example, the tip of the arrow or the center of the crosshairs.")
  1265.      (image_instance, x, y)
  1266.      Lisp_Object image_instance, x, y;
  1267. {
  1268.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1269.   if (!NILP (x))
  1270.     CHECK_INT (x, 0);
  1271.   if (!NILP (y))
  1272.     CHECK_INT (y, 0);
  1273.  
  1274.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1275.     {
  1276.     case IMAGE_MONO_PIXMAP:
  1277.     case IMAGE_COLOR_PIXMAP:
  1278.     case IMAGE_CURSOR:
  1279.       {
  1280.     struct Lisp_Image_Instance *p;
  1281.     
  1282.     p = XIMAGE_INSTANCE (image_instance);
  1283.     IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (p) = x;
  1284.     IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (p) = y;
  1285.     break;
  1286.       }
  1287.  
  1288.     default:
  1289.       signal_simple_error ("Cannot set hotspot of non-pixmap image-instance",
  1290.                image_instance);
  1291.     }
  1292.  
  1293.   return Qnil;
  1294. }
  1295.  
  1296. DEFUN ("image-instance-hotspot-x", Fimage_instance_hotspot_x,
  1297.        Simage_instance_hotspot_x, 1, 1, 0,
  1298.        "Return the X coordinate of the image instance's hotspot.\n\
  1299. See `set-image-instance-hotspot'.")
  1300.      (image_instance)
  1301.      Lisp_Object image_instance;
  1302. {
  1303.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1304.  
  1305.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1306.     {
  1307.     case IMAGE_MONO_PIXMAP:
  1308.     case IMAGE_COLOR_PIXMAP:
  1309.     case IMAGE_CURSOR:
  1310.       return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X (image_instance);
  1311.  
  1312.     default:
  1313.       return Qnil;
  1314.     }
  1315. }
  1316.  
  1317. DEFUN ("image-instance-hotspot-y", Fimage_instance_hotspot_y,
  1318.        Simage_instance_hotspot_y, 1, 1, 0,
  1319.        "Return the Y coordinate of the image instance's hotspot.\n\
  1320. See `set-image-instance-hotspot'.")
  1321.      (image_instance)
  1322.      Lisp_Object image_instance;
  1323. {
  1324.   CHECK_IMAGE_INSTANCE (image_instance, 0);
  1325.  
  1326.   switch (XIMAGE_INSTANCE_TYPE (image_instance))
  1327.     {
  1328.     case IMAGE_MONO_PIXMAP:
  1329.     case IMAGE_COLOR_PIXMAP:
  1330.     case IMAGE_CURSOR:
  1331.       return XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (image_instance);
  1332.  
  1333.     default:
  1334.       return Qnil;
  1335.     }
  1336. }
  1337.  
  1338.  
  1339. /****************************************************************************
  1340.  *                         Image Specifier Object                           *
  1341.  ****************************************************************************/
  1342.  
  1343. DEFINE_SPECIFIER_TYPE (image);
  1344.  
  1345. static void
  1346. image_create (Lisp_Object obj)
  1347. {
  1348.   struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
  1349.  
  1350.   IMAGE_SPECIFIER_ALLOWED (image) = ~0; /* all are allowed */
  1351.   IMAGE_SPECIFIER_FACE (image) = Qnil;
  1352.   IMAGE_SPECIFIER_FACE_PROPERTY (image) = Qnil;
  1353. }
  1354.  
  1355. static void
  1356. image_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
  1357. {
  1358.   struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
  1359.  
  1360.   ((markobj) (IMAGE_SPECIFIER_FACE (image)));
  1361.   ((markobj) (IMAGE_SPECIFIER_FACE_PROPERTY (image)));
  1362. }
  1363.  
  1364. /* Given a specification for an image, return an instance of
  1365.    the image which matches the given instantiator and which can be
  1366.    displayed in the given domain. */
  1367.  
  1368. static Lisp_Object
  1369. image_instantiate_1 (Lisp_Object device, Lisp_Object instantiator,
  1370.              int dest_mask, int no_quit)
  1371. {
  1372.   return instantiate_image_instantiator (device, instantiator,
  1373.                      dest_mask, 1);
  1374. }
  1375.  
  1376. static Lisp_Object
  1377. image_instantiate (Lisp_Object specifier, Lisp_Object domain,
  1378.            Lisp_Object instantiator, int no_quit)
  1379. {
  1380.   Lisp_Object device = DFW_DEVICE (domain);
  1381.   struct device *d = XDEVICE (device);
  1382.   int dest_mask = XIMAGE_SPECIFIER_ALLOWED (specifier);
  1383.  
  1384.   if (IMAGE_INSTANCEP (instantiator))
  1385.     {
  1386.       /* make sure that the image instance's device and type are
  1387.      matching. */
  1388.  
  1389.       if (EQ (device, XIMAGE_INSTANCE_DEVICE (instantiator)))
  1390.     {
  1391.       int mask =
  1392.         image_instance_type_to_mask (XIMAGE_INSTANCE_TYPE (instantiator));
  1393.       if (mask & dest_mask)
  1394.         return instantiator;
  1395.       else
  1396.         return Qunbound;
  1397.     }
  1398.       else
  1399.     return Qunbound;
  1400.     }
  1401.   else
  1402.     {
  1403.       Lisp_Object instance;
  1404.       Lisp_Object subtable;
  1405.  
  1406.       /* First look in the hash table. */
  1407.       subtable = Fgethash (make_number (dest_mask), d->image_instance_cache,
  1408.                Qunbound);
  1409.       if (UNBOUNDP (subtable))
  1410.     {
  1411.       /* For the image instance cache, we do comparisons with EQ rather
  1412.          than with EQUAL, as we do for color and font names.
  1413.          The reasons are:
  1414.  
  1415.          1) pixmap data can be very long, and thus the hashing and
  1416.          comparing will take awhile.
  1417.          2) It's not so likely that we'll run into things that are EQUAL
  1418.          but not EQ (that can happen a lot with faces, because their
  1419.          specifiers are copied around); but pixmaps tend not to be
  1420.          in faces.
  1421.          3) pixmap data could be in vector form as well as in string
  1422.          form, and so writing a hash function would be trickier.
  1423.        */
  1424.  
  1425.       subtable = make_lisp_hashtable (20, 0, 0, HASHTABLE_KEY_WEAK);
  1426.       Fputhash (make_number (dest_mask), subtable,
  1427.             d->image_instance_cache);
  1428.       instance = Qunbound;
  1429.     }
  1430.       else
  1431.     instance = Fgethash (instantiator, subtable, Qunbound);
  1432.  
  1433.       if (UNBOUNDP (instance))
  1434.     {
  1435.       /* make sure we cache the failures, too. */
  1436.       instance = image_instantiate_1 (device, instantiator, dest_mask,
  1437.                       no_quit);
  1438.       Fputhash (instantiator, instance, subtable);
  1439.     }
  1440.  
  1441.       return (NILP (instance) ? Qunbound : instance);
  1442.     }
  1443. }
  1444.  
  1445. /* Validate an image instantiator. */
  1446.  
  1447. static int
  1448. image_validate (Lisp_Object instantiator, int no_error)
  1449. {
  1450.   if (IMAGE_INSTANCEP (instantiator))
  1451.     return 1;
  1452.  return validate_image_instantiator (instantiator, no_error);
  1453. }
  1454.  
  1455. static void
  1456. image_after_change (Lisp_Object specifier, Lisp_Object locale)
  1457. {
  1458.   Lisp_Object face = IMAGE_SPECIFIER_FACE (XIMAGE_SPECIFIER (specifier));
  1459.   Lisp_Object property =
  1460.     IMAGE_SPECIFIER_FACE_PROPERTY (XIMAGE_SPECIFIER (specifier));
  1461.   if (!NILP (face))
  1462.     face_property_was_changed (face, property, locale);
  1463. }
  1464.  
  1465. void
  1466. set_image_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
  1467. {
  1468.   struct Lisp_Specifier *image = XIMAGE_SPECIFIER (obj);
  1469.  
  1470.   IMAGE_SPECIFIER_FACE (image) = face;
  1471.   IMAGE_SPECIFIER_FACE_PROPERTY (image) = property;
  1472. }
  1473.  
  1474. static Lisp_Object
  1475. image_going_to_add (Lisp_Object specifier, Lisp_Object locale,
  1476.             Lisp_Object tag_set, Lisp_Object instantiator)
  1477. {
  1478.   Lisp_Object possible_device_types = Qnil;
  1479.   Lisp_Object rest;
  1480.   Lisp_Object retlist = Qnil;
  1481.   struct gcpro gcpro1, gcpro2;
  1482.  
  1483.   LIST_LOOP (rest, Vdevice_type_list)
  1484.     {
  1485.       Lisp_Object devtype = XCAR (rest);
  1486.       if (!NILP (memq_no_quit (devtype, tag_set)))
  1487.     possible_device_types = Fcons (devtype, possible_device_types);
  1488.     }
  1489.  
  1490.   if (XINT (Flength (possible_device_types)) > 1)
  1491.     /* two conflicting device types specified */
  1492.     return Qnil;
  1493.  
  1494.   if (NILP (possible_device_types))
  1495.     possible_device_types = Vdevice_type_list;
  1496.  
  1497.   GCPRO2 (retlist, possible_device_types);
  1498.  
  1499.   LIST_LOOP (rest, possible_device_types)
  1500.     {
  1501.       Lisp_Object newinst;
  1502.       Lisp_Object devtype = XCAR (rest);
  1503.  
  1504.       newinst = normalize_image_instantiator (instantiator, devtype, 1);
  1505.       if (!NILP (newinst))
  1506.     {
  1507.       Lisp_Object newtag;
  1508.       if (NILP (memq_no_quit (devtype, tag_set)))
  1509.         newtag = Fcons (devtype, tag_set);
  1510.       else
  1511.         newtag = tag_set;
  1512.       retlist = Fcons (Fcons (newtag, newinst), retlist);
  1513.     }
  1514.     }
  1515.  
  1516.   UNGCPRO;
  1517.  
  1518.   return retlist;
  1519. }
  1520.  
  1521. DEFUN ("image-specifier-p", Fimage_specifier_p, Simage_specifier_p, 1, 1, 0,
  1522.        "Return non-nil if OBJECT is an image specifier.\n\
  1523. \n\
  1524. An image specifier is used for images (pixmaps and the like).  It is used\n\
  1525. to describe the actual image in a glyph.  It is instanced as an image-\n\
  1526. instance.\n\
  1527. \n\
  1528. An image instantiator should be a string or a vector of the form\n\
  1529. \n\
  1530.  [TYPE :KEYWORD VALUE ...]\n\
  1531. \n\
  1532. i.e. a type symbol followed by zero or more alternating keyword-value\n\
  1533. pairs.  TYPE should be one of\n\
  1534. \n\
  1535. 'nothing\n\
  1536.   (Don't display anything; no keywords are valid for this.)\n\
  1537. 'string\n\
  1538.   (Display this image as a text string.)\n\
  1539. 'formatted-string\n\
  1540.   (Display this image as a text string, with replaceable fields;\n\
  1541.   #### not implemented in 19.13.)\n\
  1542. 'xbm\n\
  1543.   (An X bitmap; only if X support was compiled into this XEmacs.)\n\
  1544. 'xpm\n\
  1545.   (An XPM pixmap; only if XPM support was compiled into this XEmacs.)\n\
  1546. 'xface\n\
  1547.   (An X-Face bitmap, used to encode people's faces in e-mail messages;\n\
  1548.   only if X-Face support was compiled into this XEmacs.)\n\
  1549. 'gif\n\
  1550.   (A GIF87 or GIF89 image; only if GIF support was compiled into this\n\
  1551.    XEmacs.)\n\
  1552. 'jpeg\n\
  1553.   (A JPEG image; only if JPEG support was compiled into this XEmacs.)\n\
  1554. 'png\n\
  1555.   (A PNG/GIF24 image; only if PNG support was compiled into this XEmacs.)\n\
  1556. 'autodetect\n\
  1557.   (XEmacs tries to guess what format the data is in.  If X support\n\
  1558.   exists, the data string will be checked to see if it names a filename.\n\
  1559.   If so, and this filename contains XBM or XPM data, the appropriate\n\
  1560.   sort of pixmap will be created.  Otherwise, the image will be displayed\n\
  1561.   as a string.  If no X support exists, the image will always be displayed\n\
  1562.   as a string.)\n\
  1563. \n\
  1564. The valid keywords are:\n\
  1565. \n\
  1566. :data\n\
  1567.   (Inline data.  For most formats above, this should be a string.  For\n\
  1568.   XBM images, this should be a cons of three elements: width, height, and\n\
  1569.   a string of bit data.)\n\
  1570. :file\n\
  1571.   (Data is contained in a file.  The value is the name of this file.\n\
  1572.   If both :data and :file are specified, the image is created from\n\
  1573.   what is specified in :data and the string in :file becomes the\n\
  1574.   value of the `image-instance-file-name' function when applied to\n\
  1575.   the resulting image-instance.)\n\
  1576. :mask-data\n\
  1577.   (Only for XBM images.  This specifies a mask to be used with the\n\
  1578.   bitmap.  The format is a cons of width, height, and bits, like for\n\
  1579.   :data.)\n\
  1580. :mask-file\n\
  1581.   (Only for XBM images.  This specifies a file containing the mask data.)\n\
  1582. :color-symbols\n\
  1583.   (Only for XPM images.  This specifies an alist that maps strings\n\
  1584.   that specify symbolic color names to the actual color to be used\n\
  1585.   for that symbolic color (in the form of a string or a color-specifier\n\
  1586.   object).  If this is not specified, the contents of `xpm-color-symbols'\n\
  1587.   are used to generate the alist.)\n\
  1588. \n\
  1589. If instead of a vector, the instantiator is a string, it will be looked\n\
  1590. up according to the specs in the `device-type-image-conversion-list' (q.v.)\n\
  1591. for the device type of the domain over which the image is being\n\
  1592. instantiated.\n\
  1593. \n\
  1594. If the instantiator is a string, it will be read in at the time that the\n\
  1595. instantiator is added to the image, and the instantiator will be converted\n\
  1596. into one of the [FILENAME ...] forms.  This implies that the file must exist\n\
  1597. when the instantiator is added to the image, but does not need to exist at\n\
  1598. any other time (e.g. it may be a temporary file).")
  1599.      (object)
  1600.      Lisp_Object object;
  1601. {
  1602.   return (IMAGE_SPECIFIERP (object) ? Qt : Qnil);
  1603. }
  1604.  
  1605.  
  1606. /****************************************************************************
  1607.  *                             Glyph Object                                 *
  1608.  ****************************************************************************/
  1609.  
  1610. static Lisp_Object mark_glyph (Lisp_Object, void (*) (Lisp_Object));
  1611. static void print_glyph (Lisp_Object, Lisp_Object, int);
  1612. static int glyph_equal (Lisp_Object, Lisp_Object, int depth);
  1613. static unsigned long glyph_hash (Lisp_Object obj, int depth);
  1614. static int glyph_getprop (Lisp_Object obj, Lisp_Object prop,
  1615.              Lisp_Object *value_out);
  1616. static int glyph_putprop (Lisp_Object obj, Lisp_Object prop,
  1617.               Lisp_Object value);
  1618. static int glyph_remprop (Lisp_Object obj, Lisp_Object prop);
  1619. static Lisp_Object glyph_props (Lisp_Object obj);
  1620. DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("glyph", glyph,
  1621.                       mark_glyph, print_glyph, 0,
  1622.                       glyph_equal, glyph_hash,
  1623.                       glyph_getprop, glyph_putprop,
  1624.                       glyph_remprop, glyph_props,
  1625.                       struct Lisp_Glyph);
  1626.  
  1627. static Lisp_Object
  1628. mark_glyph (Lisp_Object obj, void (*markobj) (Lisp_Object))
  1629. {
  1630.   struct Lisp_Glyph *glyph =  XGLYPH (obj);
  1631.  
  1632.   ((markobj) (glyph->image));
  1633.   ((markobj) (glyph->contrib_p));
  1634.   ((markobj) (glyph->baseline));
  1635.   ((markobj) (glyph->face));
  1636.  
  1637.   return (glyph->plist);
  1638. }
  1639.  
  1640. static void
  1641. print_glyph (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  1642. {
  1643.   struct Lisp_Glyph *glyph = XGLYPH (obj);
  1644.   char buf[20];
  1645.  
  1646.   if (print_readably)
  1647.     error ("printing unreadable object #<glyph 0x%x>", glyph->header.uid);
  1648.  
  1649.   write_c_string ("#<glyph (", printcharfun);
  1650.   print_internal (Fglyph_type (obj), printcharfun, 0);
  1651.   write_c_string (") ", printcharfun);
  1652.   print_internal (glyph->image, printcharfun, 1);
  1653.   sprintf (buf, "0x%x>", glyph->header.uid);
  1654.   write_c_string (buf, printcharfun);
  1655. }
  1656.  
  1657. /* Glyphs are equal if all of their display attributes are equal.  We
  1658.    don't compare names or doc-strings, because that would make equal
  1659.    be eq.
  1660.  
  1661.    This isn't concerned with "unspecified" attributes, that's what
  1662.    #'glyph-differs-from-default-p is for. */
  1663. static int
  1664. glyph_equal (Lisp_Object o1, Lisp_Object o2, int depth)
  1665. {
  1666.   struct Lisp_Glyph *g1 = XGLYPH (o1);
  1667.   struct Lisp_Glyph *g2 = XGLYPH (o2);
  1668.  
  1669.   depth++;
  1670.  
  1671.   if (!internal_equal (g1->image, g2->image, depth) ||
  1672.       !internal_equal (g1->contrib_p, g2->contrib_p, depth) ||
  1673.       !internal_equal (g1->baseline, g2->baseline, depth) ||
  1674.       !internal_equal (g1->face, g2->face, depth) ||
  1675.       plists_differ (g1->plist, g2->plist, depth + 1))
  1676.     return 0;
  1677.  
  1678.   return 1;
  1679. }
  1680.  
  1681. static unsigned long
  1682. glyph_hash (Lisp_Object obj, int depth)
  1683. {
  1684.   struct Lisp_Glyph *g = XGLYPH (obj);
  1685.  
  1686.   depth++;
  1687.  
  1688.   /* No need to hash all of the elements; that would take too long.
  1689.      Just hash the most common ones. */
  1690.   return HASH2 (internal_hash (g->image, depth),
  1691.         internal_hash (g->face, depth));
  1692. }
  1693.  
  1694. static int
  1695. glyph_getprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object *value_out)
  1696. {
  1697.   struct Lisp_Glyph *g = XGLYPH (obj);
  1698.  
  1699. #define FROB(propprop)                             \
  1700. do {                                    \
  1701.   if (EQ (prop, Q##propprop))                        \
  1702.     {                                    \
  1703.       *value_out = g->propprop;                        \
  1704.       return 1;                                \
  1705.     }                                    \
  1706. } while (0)
  1707.  
  1708.   FROB (image);
  1709.   FROB (contrib_p);
  1710.   FROB (baseline);
  1711.   FROB (face);
  1712.  
  1713. #undef FROB
  1714.  
  1715.   return internal_getf (g->plist, prop, value_out);
  1716. }
  1717.  
  1718. static int
  1719. glyph_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value)
  1720. {
  1721.   struct Lisp_Glyph *g = XGLYPH (obj);
  1722.  
  1723. #define FROB(propprop)                             \
  1724. do {                                    \
  1725.   if (EQ (prop, Q##propprop))                        \
  1726.     return 0;                                \
  1727. } while (0)
  1728.  
  1729.   FROB (image);
  1730.   FROB (contrib_p);
  1731.   FROB (baseline);
  1732.  
  1733. #undef FROB
  1734.  
  1735.   if (EQ (prop, Qface))
  1736.     {
  1737.       value = Fget_face (value);
  1738.       g->face = value;
  1739.       return 1;
  1740.     }
  1741.  
  1742.   internal_putf (&g->plist, prop, value);
  1743.   return 1;
  1744. }
  1745.  
  1746. static int
  1747. glyph_remprop (Lisp_Object obj, Lisp_Object prop)
  1748. {
  1749.   struct Lisp_Glyph *g = XGLYPH (obj);
  1750.  
  1751. #define FROB(propprop)                             \
  1752. do {                                    \
  1753.   if (EQ (prop, Q##propprop))                        \
  1754.     return -1;                                \
  1755. } while (0)
  1756.  
  1757.   FROB (image);
  1758.   FROB (contrib_p);
  1759.   FROB (baseline);
  1760.  
  1761.   if (EQ (prop, Qface))
  1762.     {
  1763.       g->face = Qnil;
  1764.       return 1;
  1765.     }
  1766.  
  1767. #undef FROB
  1768.   return internal_remprop (&g->plist, prop);
  1769. }
  1770.  
  1771. static Lisp_Object
  1772. glyph_props (Lisp_Object obj)
  1773. {
  1774.   struct Lisp_Glyph *g = XGLYPH (obj);
  1775.   Lisp_Object result = Qnil;
  1776.  
  1777. #define FROB(propprop)                             \
  1778. do {                                    \
  1779.   result = Fcons (g->propprop, Fcons (Q##propprop, result));        \
  1780. } while (0)
  1781.  
  1782.   /* backwards order; we reverse it below */
  1783.   FROB (face);
  1784.   FROB (baseline);
  1785.   FROB (contrib_p);
  1786.   FROB (image);
  1787.  
  1788. #undef FROB
  1789.   return nconc2 (Fnreverse (result), Fcopy_sequence (g->plist));
  1790. }
  1791.  
  1792. static Lisp_Object
  1793. make_glyph (enum glyph_type type)
  1794. {
  1795.   Lisp_Object obj = Qnil;
  1796.   struct Lisp_Glyph *g =
  1797.     alloc_lcrecord (sizeof (struct Lisp_Glyph), lrecord_glyph);
  1798.   
  1799.   g->type = type;
  1800.   g->image = Fmake_specifier (Qimage);
  1801.   switch (g->type)
  1802.     {
  1803.     case GLYPH_BUFFER:
  1804.       XIMAGE_SPECIFIER_ALLOWED (g->image) =
  1805.     IMAGE_NOTHING_MASK | IMAGE_TEXT_MASK | IMAGE_MONO_PIXMAP_MASK |
  1806.       IMAGE_COLOR_PIXMAP_MASK | IMAGE_SUBWINDOW_MASK;
  1807.       break;
  1808.     case GLYPH_CURSOR:
  1809.       XIMAGE_SPECIFIER_ALLOWED (g->image) = IMAGE_CURSOR_MASK;
  1810.       break;
  1811.     case GLYPH_ICON:
  1812.       XIMAGE_SPECIFIER_ALLOWED (g->image) = IMAGE_MONO_PIXMAP_MASK |
  1813.     IMAGE_COLOR_PIXMAP_MASK;
  1814.       break;
  1815.     default:
  1816.       abort ();
  1817.     }
  1818.  
  1819.   set_specifier_fallback (g->image, list1 (Fcons (Qnil, Vthe_nothing_vector)));
  1820.   g->contrib_p = Fmake_specifier (Qboolean);
  1821.   set_specifier_fallback (g->contrib_p, list1 (Fcons (Qnil, Qt)));
  1822.   /* #### should have a specifier for the following */
  1823.   g->baseline = Fmake_specifier (Qgeneric);
  1824.   set_specifier_fallback (g->baseline, list1 (Fcons (Qnil, Qnil)));
  1825.   g->face = Qnil;
  1826.   g->plist = Qnil;
  1827.  
  1828.   XSETGLYPH (obj, g);
  1829.   return obj;
  1830. }
  1831.  
  1832. static enum glyph_type
  1833. decode_glyph_type (Lisp_Object type, int no_error)
  1834. {
  1835.   if (NILP (type))
  1836.     return GLYPH_BUFFER;
  1837.  
  1838.   if (!no_error)
  1839.     CHECK_SYMBOL (type, 0);
  1840.  
  1841.   if (EQ (type, Qbuffer))
  1842.     return GLYPH_BUFFER;
  1843.   if (EQ (type, Qcursor))
  1844.     return GLYPH_CURSOR;
  1845.   if (EQ (type, Qicon))
  1846.     return GLYPH_ICON;
  1847.  
  1848.   if (!no_error)
  1849.     signal_simple_error ("Invalid glyph type", type);
  1850.   return GLYPH_UNKNOWN;
  1851. }
  1852.  
  1853. static int
  1854. valid_glyph_type_p (Lisp_Object type)
  1855. {
  1856.   if (!NILP (memq_no_quit (type, Vglyph_type_list)))
  1857.     return 1;
  1858.   return 0;
  1859. }
  1860.  
  1861. DEFUN ("valid-glyph-type-p", Fvalid_glyph_type_p,
  1862.        Svalid_glyph_type_p, 1, 1, 0,
  1863.        "Given an GLYPH-TYPE, return non-nil if it is valid.\n\
  1864. Valid types are some subset of 'nothing, 'text, 'mono-pixmap, 'color-pixmap,\n\
  1865. 'cursor, and 'subwindow, depending on how XEmacs was compiled.")
  1866.      (glyph_type)
  1867.      Lisp_Object glyph_type;
  1868. {
  1869.   if (valid_glyph_type_p (glyph_type))
  1870.     return Qt;
  1871.   else
  1872.     return Qnil;
  1873. }
  1874.  
  1875. DEFUN ("glyph-type-list", Fglyph_type_list,
  1876.        Sglyph_type_list,
  1877.        0, 0, 0,
  1878.        "Return a list of valid glyph types.")
  1879.      ()
  1880. {
  1881.   return Fcopy_sequence (Vglyph_type_list);
  1882. }
  1883.  
  1884. DEFUN ("make-glyph-internal", Fmake_glyph_internal, Smake_glyph_internal,
  1885.        0, 1, 0,
  1886.        "Create a new, uninitialized glyph.")
  1887.      (type)
  1888.      Lisp_Object type;
  1889. {
  1890.   enum glyph_type typeval = decode_glyph_type (type, 0);
  1891.   return make_glyph (typeval);
  1892. }
  1893.  
  1894. DEFUN ("glyphp", Fglyphp, Sglyphp, 1, 1, 0,
  1895.        "Return non-nil if OBJECT is a glyph.\n\
  1896. \n\
  1897. A glyph is an object used for pixmaps and the like.  It is used\n\
  1898. in begin-glyphs and end-glyphs attached to extents, in marginal and textual\n\
  1899. annotations, in overlay arrows (overlay-arrow-* variables), in toolbar\n\
  1900. buttons, and the like.  Its image is described using an image specifier --\n\
  1901. see `image-specifier-p'.")
  1902.      (object)
  1903.      Lisp_Object object;
  1904. {
  1905.   return GLYPHP (object) ? Qt : Qnil;
  1906. }
  1907.  
  1908. DEFUN ("glyph-type", Fglyph_type, Sglyph_type,
  1909.        1, 1, 0,
  1910.        "Return the type of the given glyph.\n\
  1911. The return value will be one of 'buffer, 'cursor, or 'icon.")
  1912.   (glyph)
  1913.   Lisp_Object glyph;
  1914. {
  1915.   CHECK_GLYPH (glyph, 0);
  1916.   switch (XGLYPH_TYPE (glyph))
  1917.     {
  1918.     case GLYPH_BUFFER:
  1919.       return Qbuffer;
  1920.     case GLYPH_CURSOR:
  1921.       return Qcursor;
  1922.     case GLYPH_ICON:
  1923.       return Qicon;
  1924.     default:
  1925.       abort ();
  1926.     }
  1927.  
  1928.   return Qnil; /* not reached */
  1929. }
  1930.  
  1931. /*****************************************************************************
  1932.  glyph_width
  1933.  
  1934.  Return the width of the given GLYPH on the given WINDOW.  If the
  1935.  instance is a string then the width is calculated using the font of
  1936.  the given FACE.
  1937.  ****************************************************************************/
  1938. unsigned short
  1939. glyph_width (Lisp_Object glyph, face_index findex, int framep,
  1940.          Lisp_Object window)
  1941. {
  1942.   Lisp_Object instance;
  1943.   Lisp_Object frame = XWINDOW (window)->frame;
  1944.  
  1945.   /* #### We somehow need to distinguish between the user causing this
  1946.      error condition and a bug causing it. */
  1947.   if (!GLYPHP (glyph))
  1948.     return 0;
  1949.   else
  1950.     instance = glyph_image_instance (glyph, window, 1);
  1951.  
  1952.   switch (XIMAGE_INSTANCE_TYPE (instance))
  1953.     {
  1954.     case IMAGE_TEXT:
  1955.       {
  1956.     struct device *d = XDEVICE (XFRAME (frame)->device);
  1957.     struct Lisp_String *str =
  1958.       XSTRING (XIMAGE_INSTANCE_TEXT_STRING (instance));
  1959.     Lisp_Object font;
  1960.  
  1961.     /* #### more lossage.  See add_glyph_rune(). */
  1962. #ifdef MULE
  1963.     lose; /* !!#### */
  1964. #else
  1965.     int i;
  1966.     int len = string_length (str);
  1967.     Emchar *bogobogo = (Emchar *) alloca (len * sizeof (Emchar));
  1968.     for (i = 0; i < len; i++)
  1969.       bogobogo[i] = (Emchar) string_byte (str, i);
  1970.     
  1971.     if (framep)
  1972.       font = FACE_FONT (Vdefault_face, frame);
  1973.     else
  1974.       font = FACE_CACHE_ELEMENT_FONT (XWINDOW (window), findex);
  1975.     
  1976.     return (DEVMETH (d, text_width,
  1977.              (XWINDOW (window), font, bogobogo, len)));
  1978. #endif
  1979.       }
  1980.  
  1981.     case IMAGE_MONO_PIXMAP:
  1982.     case IMAGE_COLOR_PIXMAP:
  1983.     case IMAGE_CURSOR:
  1984.       return XIMAGE_INSTANCE_PIXMAP_WIDTH (instance);
  1985.  
  1986.     case IMAGE_NOTHING:
  1987.       return 0;
  1988.  
  1989.     case IMAGE_SUBWINDOW:
  1990.       /* #### implement me */
  1991.       return 0;
  1992.  
  1993.     default:
  1994.       abort ();
  1995.       return 0;
  1996.     }
  1997. }
  1998.  
  1999. DEFUN ("glyph-width", Fglyph_width, Sglyph_width, 1, 2, 0,
  2000.        "Return the width of GLYPH on WINDOW.\n\
  2001. This may not be exact as it does not take into account all of the context\n\
  2002. that redisplay will.")
  2003.      (glyph, window)
  2004.      Lisp_Object glyph, window;
  2005. {
  2006.   XSETWINDOW (window, decode_window (window));
  2007.   CHECK_GLYPH (glyph, 0);
  2008.  
  2009.   return (make_number (glyph_width (glyph, DEFAULT_INDEX, 0, window)));
  2010. }
  2011.  
  2012. #define RETURN_ASCENT    0
  2013. #define RETURN_DESCENT    1
  2014. #define RETURN_HEIGHT    2
  2015.  
  2016. Lisp_Object
  2017. glyph_image_instance (Lisp_Object glyph, Lisp_Object domain,
  2018.               int no_error_or_quit)
  2019. {
  2020.   Lisp_Object specifier = GLYPH_IMAGE (XGLYPH (glyph));
  2021.  
  2022.   /* This can never return Qunbound.  All glyphs have 'nothing as
  2023.      a fallback. */
  2024.   return specifier_instance (specifier, domain, no_error_or_quit, 0);
  2025. }
  2026.  
  2027. static unsigned short
  2028. glyph_height_internal (Lisp_Object glyph, face_index findex, int framep,
  2029.                Lisp_Object window, int function)
  2030. {
  2031.   Lisp_Object instance;
  2032.   Lisp_Object frame = XWINDOW (window)->frame;
  2033.  
  2034.   if (!GLYPHP (glyph))
  2035.     return 0;
  2036.   else
  2037.     instance = glyph_image_instance (glyph, window, 1);
  2038.  
  2039.   switch (XIMAGE_INSTANCE_TYPE (instance))
  2040.     {
  2041.     case IMAGE_TEXT:
  2042.       {
  2043.     struct device *d = XDEVICE (XFRAME (frame)->device);
  2044.     struct font_metric_info fm;
  2045.     Lisp_Object font;
  2046.     
  2047.     if (framep)
  2048.       font = FACE_FONT (Vdefault_face, frame);
  2049.     else
  2050.       font = FACE_CACHE_ELEMENT_FONT (XWINDOW (window), findex);
  2051.     
  2052.     DEVMETH (d, font_metric_info, (d, font, &fm));
  2053.     
  2054.     if (function == RETURN_ASCENT)
  2055.       return fm.ascent;
  2056.     else if (function == RETURN_DESCENT)
  2057.       return fm.descent;
  2058.     else if (function == RETURN_HEIGHT)
  2059.       return fm.ascent + fm.descent;
  2060.     else
  2061.       abort ();
  2062.     return 0;
  2063.       }
  2064.  
  2065.     case IMAGE_MONO_PIXMAP:
  2066.     case IMAGE_COLOR_PIXMAP:
  2067.     case IMAGE_CURSOR:
  2068.       /* #### Ugh ugh ugh -- temporary crap */
  2069.       if (function == RETURN_ASCENT || function == RETURN_HEIGHT)
  2070.     return XIMAGE_INSTANCE_PIXMAP_HEIGHT (instance);
  2071.       else
  2072.     return 0;
  2073.  
  2074.     case IMAGE_NOTHING:
  2075.       return 0;
  2076.  
  2077.     case IMAGE_SUBWINDOW:
  2078.       /* #### implement me */
  2079.       return 0;
  2080.  
  2081.     default:
  2082.       abort ();
  2083.       return 0;
  2084.     }
  2085. }
  2086.  
  2087. unsigned short
  2088. glyph_ascent (Lisp_Object glyph, face_index findex, int framep,
  2089.           Lisp_Object window)
  2090. {
  2091.   return glyph_height_internal (glyph, findex, framep, window, RETURN_ASCENT);
  2092. }
  2093.  
  2094. unsigned short
  2095. glyph_descent (Lisp_Object glyph, face_index findex, int framep,
  2096.            Lisp_Object window)
  2097. {
  2098.   return glyph_height_internal (glyph, findex, framep, window, RETURN_DESCENT);
  2099. }
  2100.  
  2101. /* strictly a convenience function. */
  2102. unsigned short
  2103. glyph_height (Lisp_Object glyph, face_index findex, int framep,
  2104.           Lisp_Object window)
  2105. {
  2106.   return glyph_height_internal (glyph, findex, framep, window, RETURN_HEIGHT);
  2107. }
  2108.  
  2109. DEFUN ("glyph-ascent", Fglyph_ascent, Sglyph_ascent, 1, 2, 0,
  2110.        "Return the ascent value of GLYPH on WINDOW.\n\
  2111. This may not be exact as it does not take into account all of the context\n\
  2112. that redisplay will.")
  2113.      (glyph, window)
  2114.      Lisp_Object glyph, window;
  2115. {
  2116.   XSETWINDOW (window, decode_window (window));
  2117.   CHECK_GLYPH (glyph, 0);
  2118.  
  2119.   return (make_number (glyph_ascent (glyph, DEFAULT_INDEX, 0, window)));
  2120. }
  2121.  
  2122. DEFUN ("glyph-descent", Fglyph_descent, Sglyph_descent, 1, 2, 0,
  2123.        "Return the descent value of GLYPH on WINDOW.\n\
  2124. This may not be exact as it does not take into account all of the context\n\
  2125. that redisplay will.")
  2126.      (glyph, window)
  2127.      Lisp_Object glyph, window;
  2128. {
  2129.   XSETWINDOW (window, decode_window (window));
  2130.   CHECK_GLYPH (glyph, 0);
  2131.  
  2132.   return (make_number (glyph_descent (glyph, DEFAULT_INDEX, 0, window)));
  2133. }
  2134.  
  2135. /* This is redundant but I bet a lot of people expect it to exist. */
  2136. DEFUN ("glyph-height", Fglyph_height, Sglyph_height, 1, 2, 0,
  2137.        "Return the height of GLYPH on WINDOW.\n\
  2138. This may not be exact as it does not take into account all of the context\n\
  2139. that redisplay will.")
  2140.      (glyph, window)
  2141.      Lisp_Object glyph, window;
  2142. {
  2143.   XSETWINDOW (window, decode_window (window));
  2144.   CHECK_GLYPH (glyph, 0);
  2145.  
  2146.   return (make_number (glyph_height (glyph, DEFAULT_INDEX, 0, window)));
  2147. }
  2148.  
  2149. #undef RETURN_ASCENT
  2150. #undef RETURN_DESCENT
  2151. #undef RETURN_HEIGHT
  2152.  
  2153. /* #### do we need to cache this info to speed things up? */
  2154.  
  2155. Lisp_Object
  2156. glyph_baseline (Lisp_Object glyph, Lisp_Object domain)
  2157. {
  2158.   if (!GLYPHP (glyph))
  2159.     return Qnil;
  2160.   else
  2161.     {
  2162.       Lisp_Object retval =
  2163.     specifier_instance_no_quit (GLYPH_BASELINE (XGLYPH (glyph)),
  2164.                     domain, 0);
  2165.       if (!NILP (retval) && !INTP (retval))
  2166.     retval = Qnil;
  2167.       else if (INTP (retval))
  2168.     {
  2169.       if (XINT (retval) < 0)
  2170.         retval = Qzero;
  2171.       if (XINT (retval) > 100)
  2172.         retval = make_number (100);
  2173.     }
  2174.       return retval;
  2175.     }
  2176. }
  2177.  
  2178. Lisp_Object
  2179. glyph_face (Lisp_Object glyph, Lisp_Object domain)
  2180. {
  2181.   /* #### Domain parameter not currently used but it will be */
  2182.   if (!GLYPHP (glyph))
  2183.     return Qnil;
  2184.   else
  2185.     return GLYPH_FACE (XGLYPH (glyph));
  2186. }
  2187.  
  2188. int
  2189. glyph_contrib_p (Lisp_Object glyph, Lisp_Object domain)
  2190. {
  2191.   if (!GLYPHP (glyph))
  2192.     return 0;
  2193.   else
  2194.     return (!NILP (specifier_instance_no_quit
  2195.            (GLYPH_CONTRIB_P (XGLYPH (glyph)), domain, 0)));
  2196. }
  2197.  
  2198.  
  2199. /*****************************************************************************
  2200.  *                     glyph cache element functions                         *
  2201.  *****************************************************************************/
  2202.  
  2203. /*
  2204.  #### All of this is 95% copied from face cache elements.
  2205.       Consider consolidating.
  2206.  #### We need to add a dirty flag to the glyphs.
  2207.  */
  2208.  
  2209. void
  2210. mark_glyph_cache_elements (glyph_cache_element_dynarr *elements,
  2211.                void (*markobj) (Lisp_Object))
  2212. {
  2213.   int elt;
  2214.  
  2215.   if (!elements)
  2216.     return;
  2217.  
  2218.   for (elt = 0; elt < Dynarr_length (elements); elt++)
  2219.     {
  2220.       struct glyph_cache_element *inst = Dynarr_atp (elements, elt);
  2221.       ((markobj) (inst->glyph));
  2222.     }
  2223. }
  2224.  
  2225. static void
  2226. update_glyph_cache_element_data (struct window *w, Lisp_Object glyph,
  2227.                  struct glyph_cache_element *inst)
  2228. {
  2229.   /* #### This should be || !inst->updated */
  2230.   if (NILP (inst->glyph) || !EQ (inst->glyph, glyph))
  2231.     {
  2232.       Lisp_Object window = Qnil;
  2233.  
  2234.       XSETWINDOW (window, w);
  2235.       inst->glyph = glyph;
  2236.  
  2237. #define FROB(field)                            \
  2238.   do {                                    \
  2239.     unsigned short new_val = glyph_##field (glyph, DEFAULT_INDEX, 0, window); \
  2240.     if (inst->field != new_val)                        \
  2241.       inst->field = new_val;                        \
  2242.   } while (0)
  2243.  
  2244.     /* #### This could be sped up if we redid things to grab the glyph
  2245.        instantiation and passed it to the size functions. */
  2246.       FROB (width);
  2247.       FROB (ascent);
  2248.       FROB (descent);
  2249. #undef FROB
  2250.  
  2251.     }
  2252.  
  2253.   inst->updated = 1;
  2254. }
  2255.  
  2256. static void
  2257. add_glyph_cache_element (struct window *w, Lisp_Object glyph)
  2258. {
  2259.   struct glyph_cache_element new_inst;
  2260.  
  2261.   memset (&new_inst, 0, sizeof (struct glyph_cache_element));
  2262.   new_inst.glyph = Qnil;
  2263.  
  2264.   update_glyph_cache_element_data (w, glyph, &new_inst);
  2265.   Dynarr_add (w->glyph_cache_elements, new_inst);
  2266. }
  2267.  
  2268. static glyph_index
  2269. get_glyph_cache_element_index (struct window *w, Lisp_Object glyph)
  2270. {
  2271.   int elt;
  2272.  
  2273.   if (noninteractive)
  2274.     return 0;
  2275.  
  2276.   for (elt = 0; elt < Dynarr_length (w->glyph_cache_elements); elt++)
  2277.     {
  2278.       struct glyph_cache_element *inst =
  2279.     Dynarr_atp (w->glyph_cache_elements, elt);
  2280.  
  2281.       if (EQ (inst->glyph, glyph) && !NILP (glyph))
  2282.     {
  2283.       if (!inst->updated)
  2284.         update_glyph_cache_element_data (w, glyph, inst);
  2285.       return elt;
  2286.     }
  2287.     }
  2288.  
  2289.   /* If we didn't find the glyph, add it and then return its index. */
  2290.   add_glyph_cache_element (w, glyph);
  2291.   return elt;
  2292. }
  2293.  
  2294. void
  2295. reset_glyph_cache_elements (struct window *w)
  2296. {
  2297.   Dynarr_reset (w->glyph_cache_elements);
  2298.   get_glyph_cache_element_index (w, Vcontinuation_glyph);
  2299.   get_glyph_cache_element_index (w, Vtruncation_glyph);
  2300.   get_glyph_cache_element_index (w, Vhscroll_glyph);
  2301.   get_glyph_cache_element_index (w, Vcontrol_arrow_glyph);
  2302.   get_glyph_cache_element_index (w, Voctal_escape_glyph);
  2303.   get_glyph_cache_element_index (w, Vinvisible_text_glyph);
  2304. }
  2305.  
  2306. void
  2307. mark_glyph_cache_elements_as_not_updated (struct window *w)
  2308. {
  2309.   int elt;
  2310.  
  2311.   /* We need to have a dirty flag to tell if the glyph has changed.
  2312.      We can check to see if each glyph variable is actually a
  2313.      completely different glyph, though. */
  2314. #define FROB(glyph_obj, gindex)                        \
  2315.   update_glyph_cache_element_data (w, glyph_obj,            \
  2316.                   Dynarr_atp (w->glyph_cache_elements, gindex))
  2317.  
  2318.   FROB (Vcontinuation_glyph, CONT_GLYPH_INDEX);
  2319.   FROB (Vtruncation_glyph, TRUN_GLYPH_INDEX);
  2320.   FROB (Vhscroll_glyph, HSCROLL_GLYPH_INDEX);
  2321.   FROB (Vcontrol_arrow_glyph, CONTROL_GLYPH_INDEX);
  2322.   FROB (Voctal_escape_glyph, OCT_ESC_GLYPH_INDEX);
  2323.   FROB (Vinvisible_text_glyph, INVIS_GLYPH_INDEX);
  2324. #undef FROB
  2325.  
  2326.   for (elt = 0; elt < Dynarr_length (w->glyph_cache_elements); elt++)
  2327.     Dynarr_atp (w->glyph_cache_elements, elt)->updated = 0;
  2328. }
  2329.  
  2330.  
  2331. /*****************************************************************************
  2332.  *                              display tables                               *
  2333.  *****************************************************************************/
  2334.  
  2335. /* Get the display table for use currently on window W with face FACE.
  2336.    Precedence:
  2337.  
  2338.    -- FACE's display table
  2339.    -- W's display table (comes from specifier `current-display-table')
  2340.  
  2341.    Ignore the specified tables if they are not valid;
  2342.    if no valid table is specified, return 0.  */
  2343.  
  2344. struct Lisp_Vector *
  2345. get_display_table (struct window *w, face_index findex)
  2346. {
  2347.   Lisp_Object tem = Qnil;
  2348.  
  2349.   tem = FACE_CACHE_ELEMENT_DISPLAY_TABLE (w, findex);
  2350.   if (VECTORP (tem) && XVECTOR (tem)->size == DISP_TABLE_SIZE)
  2351.     return XVECTOR (tem);
  2352.  
  2353.   tem = w->display_table;
  2354.   if (VECTORP (tem) && XVECTOR (tem)->size == DISP_TABLE_SIZE)
  2355.     return XVECTOR (tem);
  2356.  
  2357.   return 0;
  2358. }
  2359.  
  2360.  
  2361. /*****************************************************************************
  2362.  *                              initialization                               *
  2363.  *****************************************************************************/
  2364.  
  2365. void
  2366. syms_of_glyphs (void)
  2367. {
  2368.   /* image instantiators */
  2369.  
  2370.   defsubr (&Simage_instantiator_type_list);
  2371.   defsubr (&Svalid_image_instantiator_type_p);
  2372.   defsubr (&Sset_device_type_image_conversion_list);
  2373.   defsubr (&Sdevice_type_image_conversion_list);
  2374.  
  2375.   defkeyword (&Q_file, ":file");
  2376.   defkeyword (&Q_data, ":data");
  2377.  
  2378.   /* image specifiers */
  2379.  
  2380.   defsubr (&Simage_specifier_p);
  2381.   defsymbol (&Qimage, "image");
  2382.  
  2383.   /* image instances */
  2384.  
  2385.   defsymbol (&Qimage_instancep, "image-instance-p");
  2386.   defsubr (&Smake_image_instance);
  2387.   defsubr (&Simage_instance_p);
  2388.   defsubr (&Simage_instance_type);
  2389.   defsubr (&Svalid_image_instance_type_p);
  2390.   defsubr (&Simage_instance_type_list);
  2391.   defsubr (&Simage_instance_name);
  2392.   defsubr (&Simage_instance_string);
  2393.   defsubr (&Simage_instance_file_name);
  2394.   defsubr (&Simage_instance_mask_file_name);
  2395.   defsubr (&Simage_instance_depth);
  2396.   defsubr (&Simage_instance_height);
  2397.   defsubr (&Simage_instance_width);
  2398.   defsubr (&Sset_image_instance_hotspot);
  2399.   defsubr (&Simage_instance_hotspot_x);
  2400.   defsubr (&Simage_instance_hotspot_y);
  2401.  
  2402.   /* Qnothing defined as part of the "nothing" image-instantiator
  2403.      type. */
  2404.   /* Qtext defined in general.c */
  2405.   defsymbol (&Qmono_pixmap, "mono-pixmap");
  2406.   defsymbol (&Qcolor_pixmap, "color-pixmap");
  2407.   defsymbol (&Qcursor, "cursor");
  2408.   defsymbol (&Qsubwindow, "subwindow");
  2409.  
  2410.   /* glyphs */
  2411.  
  2412.   defsymbol (&Qglyphp, "glyphp");
  2413.   defsymbol (&Qcontrib_p, "contrib-p");
  2414.   defsymbol (&Qbaseline, "baseline");
  2415.  
  2416.   defsubr (&Sglyph_type);
  2417.   defsubr (&Svalid_glyph_type_p);
  2418.   defsubr (&Sglyph_type_list);
  2419.   defsubr (&Sglyphp);
  2420.   defsubr (&Smake_glyph_internal);
  2421.   defsubr (&Sglyph_width);
  2422.   defsubr (&Sglyph_ascent);
  2423.   defsubr (&Sglyph_descent);
  2424.   defsubr (&Sglyph_height);
  2425.  
  2426.   /* Qbuffer defined in general.c. */
  2427.   /* Qcursor defined above */
  2428.   defsymbol (&Qicon, "icon");
  2429. }
  2430.  
  2431. void
  2432. specifier_type_create_image (void)
  2433. {
  2434.   /* image specifiers */
  2435.  
  2436.   INITIALIZE_SPECIFIER_TYPE_WITH_DATA (image, "image", "imagep");
  2437.  
  2438.   SPECIFIER_HAS_METHOD (image, create);
  2439.   SPECIFIER_HAS_METHOD (image, mark);
  2440.   SPECIFIER_HAS_METHOD (image, instantiate);
  2441.   SPECIFIER_HAS_METHOD (image, validate);
  2442.   SPECIFIER_HAS_METHOD (image, after_change);
  2443.   SPECIFIER_HAS_METHOD (image, going_to_add);
  2444. }
  2445.  
  2446. void
  2447. image_instantiator_type_create (void)
  2448. {
  2449.   /* image instantiators */
  2450.  
  2451.   the_image_instantiator_type_entry_dynarr =
  2452.     Dynarr_new (struct image_instantiator_type_entry);
  2453.  
  2454.   Vimage_instantiator_type_list = Qnil;
  2455.   staticpro (&Vimage_instantiator_type_list);
  2456.  
  2457.   INITIALIZE_IMAGE_INSTANTIATOR_TYPE (nothing, "nothing");
  2458.  
  2459.   IITYPE_HAS_METHOD (nothing, instantiate);
  2460.  
  2461.   INITIALIZE_IMAGE_INSTANTIATOR_TYPE (string, "string");
  2462.  
  2463.   IITYPE_HAS_METHOD (string, validate);
  2464.   IITYPE_HAS_METHOD (string, instantiate);
  2465.  
  2466.   IITYPE_VALID_KEYWORD (string, Q_data, valid_string_p);
  2467.  
  2468.   INITIALIZE_IMAGE_INSTANTIATOR_TYPE (formatted_string, "formatted-string");
  2469.  
  2470.   IITYPE_HAS_METHOD (formatted_string, validate);
  2471.   IITYPE_HAS_METHOD (formatted_string, instantiate);
  2472.  
  2473.   IITYPE_VALID_KEYWORD (formatted_string, Q_data, valid_string_p);
  2474. }
  2475.  
  2476. void
  2477. vars_of_glyphs (void)
  2478. {
  2479.   Vthe_nothing_vector = vector1 (Qnothing);
  2480.   staticpro (&Vthe_nothing_vector);
  2481.  
  2482.   /* image instances */
  2483.  
  2484.   Vimage_instance_type_list = list6 (Qnothing, Qtext, Qmono_pixmap,
  2485.                      Qcolor_pixmap, Qcursor, Qsubwindow);
  2486.   staticpro (&Vimage_instance_type_list);
  2487.  
  2488.   /* glyphs */
  2489.  
  2490.   Vglyph_type_list = list3 (Qbuffer, Qcursor, Qicon);
  2491.   staticpro (&Vglyph_type_list);
  2492.  
  2493.   /* The octal-escape glyph, control-arrow-glyph and
  2494.      invisible-text-glyph are completely initialized in glyphs.el */
  2495.  
  2496.   DEFVAR_LISP ("octal-escape-glyph", &Voctal_escape_glyph,
  2497.     "What to prefix character codes displayed in octal with.");
  2498.   Voctal_escape_glyph = Qnil;
  2499.  
  2500.   DEFVAR_LISP ("control-arrow-glyph", &Vcontrol_arrow_glyph,
  2501.     "What to use as an arrow for control characters.");
  2502.   Vcontrol_arrow_glyph = Qnil;
  2503.  
  2504.   DEFVAR_LISP ("invisible-text-glyph", &Vinvisible_text_glyph,
  2505.     "What to use to indicate the presence of invisible text.");
  2506.   Vinvisible_text_glyph = Qnil;
  2507.  
  2508.   /* Partially initialized in glyphs.el */
  2509.   DEFVAR_LISP ("hscroll-glyph", &Vhscroll_glyph,
  2510.     "What to display at the beginning of horizontally scrolled lines.");
  2511.   Vhscroll_glyph = Qnil;
  2512. }
  2513.  
  2514. void
  2515. specifier_vars_of_glyphs (void)
  2516. {
  2517.   /* display tables */
  2518.  
  2519.   DEFVAR_SPECIFIER ("current-display-table", &Vcurrent_display_table,
  2520.     "*The display table currently in use.\n\
  2521. This is a specifier; use `set-specifier' to change it.\n\
  2522. The display table is a vector created with `make-display-table'.\n\
  2523. The 256 elements control how to display each possible text character.\n\
  2524. Each value should be a string, a glyph, a vector or nil.\n\
  2525. If a value is a vector it must be composed only of strings and glyphs.\n\
  2526. nil means display the character in the default fashion.\n\
  2527. Faces can have their own, overriding display table.");
  2528.   Vcurrent_display_table = Fmake_specifier (Qgeneric);
  2529.   set_specifier_fallback (Vcurrent_display_table,
  2530.               list1 (Fcons (Qnil, Qnil)));
  2531.   set_specifier_caching (Vcurrent_display_table,
  2532.              slot_offset (struct window,
  2533.                       display_table),
  2534.              some_window_value_changed,
  2535.              0, 0);
  2536. }
  2537.  
  2538. void
  2539. complex_vars_of_glyphs (void)
  2540. {
  2541.   /* Partially initialized in glyphs-x.c, glyphs.el */
  2542.   DEFVAR_LISP ("truncation-glyph", &Vtruncation_glyph,
  2543.     "What to display at the end of truncated lines.");
  2544.   Vtruncation_glyph = Fmake_glyph_internal (Qbuffer);
  2545.  
  2546.   /* Partially initialized in glyphs-x.c, glyphs.el */
  2547.   DEFVAR_LISP ("continuation-glyph", &Vcontinuation_glyph,
  2548.     "What to display at the end of wrapped lines.");
  2549.   Vcontinuation_glyph = Fmake_glyph_internal (Qbuffer);
  2550.  
  2551.   /* Partially initialized in glyphs-x.c, glyphs.el */
  2552.   DEFVAR_LISP ("xemacs-logo", &Vxemacs_logo,
  2553.     "The glyph used to display the XEmacs logo at startup.");
  2554.   Vxemacs_logo = Fmake_glyph_internal (Qbuffer);
  2555. }
  2556.  
  2557.  
  2558.